package com.example.blog.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.blog.base.BaseEntity;
import com.example.blog.entity.MainMenu;
import com.example.blog.entity.Query;
import com.example.blog.mapper.MainMenuMapper;
import com.example.blog.service.MainMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MainMenuServiceImpl implements MainMenuService {

    @Autowired
    MainMenuMapper mainMenuMapper;

    @Override
    public Page getListByQueryPage(Query query) {
//        不想要条件查询时可以传一个空的queryWrapper对象
        QueryWrapper<MainMenu> queryWrapper = new QueryWrapper<>();
//        eq()中的内容其实就是sql中where后的内容（不一定是字段名，再多表时也可以时引用+字段 例如：m.id）
        Page<MainMenu> page = new Page<>();
//        不想进行分页时可以传 new Page<>(1, -1)
        if (query.getQueryCurrent() == null) {
            page.setCurrent(1);
            page.setSize(-1);
        } else {
            page.setCurrent(query.getQueryCurrent());
            page.setSize(query.getQuerySize());
        }
        return mainMenuMapper.getMainMenuListByQueryPage(page, queryWrapper);
    }

    @Override
    public int updateByEntity(BaseEntity baseEntity) {
        return 0;
    }

    @Override
    public int insertByEntity(BaseEntity baseEntity) {
        return 0;
    }

}
